/**
 * 该代码为vue的hook
 * @param {number} max 
 * @returns 
 * @example
 * const defer = userDefer(100)
 * 在templete中使用v-if="defer(n)"来逐帧渲染
 */
function useDefer(max) {
    const framCount = ref(1)
    let rafid
    function updateFramCount() {
        rafid = requestAnimationFrame(() => {
            framCount.value++
            if (framCount.value === max) {
                return
            }
            updateFramCount()
        })
    }
    updateFramCount()

    onUnmounted(() => {
        cancelAnimationFrame(rafid)
    })
    function defer(n) {
        return framCount.value >= n
    }

    return defer
}